<template>
	<view class="pages">
		<Loading class="loading-box" v-show="!isLoading" :isStatus='loadStatus'></Loading>
		<cu-custom bgColor="head-bg" :isBack="true" textRight="true" type="1">
			<block slot="backText" class="titilestyle">{{title}}</block>

			<block slot="right" class="" @click="clickRecord">送水记录</block>
		</cu-custom>


		<scroll-view scroll-y="true" :style="{height:scrollH+'px'}">
			<view class="head-style1">
				<view class="water-box ">
					<view class="water-box-address" :class="animationModel">

						<view class="head-item-box " @click="selectAddr">
							<view class="iconbox  middle">
								<image class="icon-img" :src="domain+'/static/img/location.png'" mode="widthFix">
								</image>
							</view>
							<view class="head-item-body "
								v-if="shopinfo.area.area_name && address.address+address.detail">
								<text
									class="text-brown text-xl c-text1">{{shopinfo.area.area_name+"-"+address.address+address.detail || ''}}
								</text>
								<view class="consignee1"><text class="c-text"> {{address.consignee || ''}}</text> <text
										class="mobile c-text margin-left ">{{address.mobile || ''}} </text></view>
							</view>
							<view class="head-item-body " v-else>
								<text class="text-brown text-xl c-text1">请选择收货地址</text>
							</view>

							<view class="right-icon  middle">
								<text class="cuIcon-right" style="font-size: 32upx;"></text>
							</view>

						</view>

						<view class="head-item-box ">

							<view class="iconbox  middle">
								<image class="icon-img" :src="domain+'/static/img/img/tong.png'" mode="widthFix">
								</image>
							</view>
							<view class="head-item-body ">
								<view class="head-item-body1">
									<picker mode="multiSelector" @change="MultiChange" @columnchange="MultiColumnChange"
										:value="multiIndex" :range="multiArray" class="picker-box">
										<view class="pickBox ">
											<view class="title ">
												{{shopinfo.goods[multiIndex[0]].cate_name}}
												{{postData.goods[0].goods_name || ""}}
											</view>

											<view class="water-box-title1">
												<view v-if="!postData.goods[0].goods_name" class="unit-box ">
													{{(postData.goods[0].goods_name)?postData.goods[0].goods_name:'请选择'}}
												</view>
												<view class="picer-right-box " v-if="postData.goods[0].is_stock==1">
													当前存量 <text class="text-blue text-bold" style="padding-left: 5upx;">
														{{(postData.goods[0].stock_num>999)?'充足':postData.goods[0].stock_num+postData.goods[0].units}}
													</text>
												</view>
												<view class="right-icon  middle">
													<text class="cuIcon-right" style="font-size: 32upx;"></text>
												</view>
											</view>
										</view>
									</picker>
								</view>
							</view>
						</view>
					</view>

					<view class="water-num-box margin-top " :class="animationModel">
						<text class="margin-left text-bold">数量</text>
						<view class="fr  water-item-right" v-if="postData.goods[0].max_quantity">
							<yp-number-box :min="1" :max="postData.goods[0].max_quantity" :value="postData.goods[0].num"
								:index="1" @change="cart">
							</yp-number-box>
						</view>
					</view>

					<view class="water-num-box margin-top " v-if="couponList.length>0" :class="animationModel"
						@click="selectCoupon">
						<text class="margin-left text-bold">水券</text>
						<view class="cu-form-group fr border" style="position:absolute;right: 0%;">
							<!-- <picker @change="PickerChange" :value="index" :range="picker"> -->
							<view class="water-box-title2">

								<view class='cu-tag round bg-red ' v-if="!cartInfo.coupon_price ">
									{{couponList.length}}张可用
								</view>
								<view class='cu-tag round bg-red ' v-else>
									-￥{{cartInfo.coupon_price || 0}}
								</view>

							</view>
							<text class="cuIcon-right"></text>
						</view>
					</view>


					<view class="water-bottom-box margin-top text-center" :class="animationModel">
						注意：配送上楼/楼下自提都需要以空桶一换一
					</view>

				</view>
			</view>



			<view class="water-box-bottom" :class="animationModel">
				<view class="pay-box middle">
					<view class="pay-box-item">
						<text class="padding-lr text-bold">使用积分</text>
						<view class="fr  water-item-right ">
							<text class="padding jifen"
								v-if="cartInfo.integral_money > 0">-￥{{cartInfo.integral_money || 0}}</text>
							<text class="padding-xs jifen" v-else>当前积分：{{userInfo.integral || 0 }}</text>

							<checkbox-group @change="useIntegral">
								<label style="margin-left: 15rpx; padding-right: 0;">
									<checkbox class="round" value="Integral" color="#000000"
										:disabled="cartInfo.online_amount==0 && is_use_integral==0" />
								</label>
							</checkbox-group>

						</view>

					</view>
					<view class="pay-box-item ">
						<text class="padding text-bold">使用余额</text>
						<view class="fr  water-item-right ">
							<text class="padding-lr jifen"
								v-if="cartInfo.user_money > 0">-￥{{cartInfo.user_money || 0}}</text>
							<text class="padding-xs jifen" v-else>共有￥{{userInfo.money | numFilter}}</text>

							<checkbox-group @change="useMoney">
								<checkbox value="user_money" color="#000000" class="round"
									:disabled="cartInfo.online_amount==0 && is_use_money==0" />
							</checkbox-group>

						</view>

					</view>

					<view class="pay-box-item " v-for="(list,i) in cartInfo.goodsList" :key="i">
						<text class="padding pay-box-item-box text-bold"> {{list['goods_name'] || '--'}} &nbsp;	x{{list.num}}</text>
						<view class="fr  water-item-right ">
							<text class="padding padding-right-0">￥{{list.goods_total_price || '--'}} </text>
						</view>

					</view>

					<view class="pay-box-item text-red" v-if="cartInfo.reduce_amount">
						<text class="padding text-bold">随机立减</text>
						<view class="fr  water-item-right ">
							<text class="padding jifen padding-right-0">- ￥{{cartInfo.reduce_amount || '--'}}</text>
						</view>

					</view>

					<view class="pay-box-item ">
						<text class="padding text-bold">应付</text>
						<view class="fr  water-item-right ">
							<text class="padding text-red padding-right-0"> ￥{{cartInfo.online_amount || 0}}</text>
						</view>

					</view>

				</view>

				<view class="pay-box middle " :class="animationModel">
					<view class="pay-box-item" v-if="postData.pay_code=='wxpay'">
						<!-- <text class="cuIcon-weixin text-xxl text-green"></text> -->
						<image :src="domain+'/static/img/img/Tencent.png'" class="weipay" mode="heightFix"></image>
						<text class="text-bold"> 微信支付</text>
						<view class="fr  water-item-right ">

							<checkbox class='round ' checked="true" disabled="true"
								:checked="checkbox[1].checked?true:false" value="B"></checkbox>
						</view>

					</view>

				</view>

				<view class="foot">

				</view>


			</view>



			<view class="pay-box middle payBox" :class="animationModel">
				<view class="pay-booton">
					<text class="text-bold padding text-xl text-space-3"> 共 <text
							class="text-blue price">{{cartInfo.online_amount || 0}}</text>
						元</text>
					<view class="fr  water-item-right ">
						<button class="cu-btn bg-blue pay-buuton-box" @click="subOrder">去支付</button>

					</view>

				</view>

			</view>

		</scroll-view>

		<uni-popup ref="coupon" type="center">
			<view style="background: #EEEEEE;">
				<view class="coupon-tit"><text>请选择优惠券</text></view>
				<scroll-view class="coupon-list sub-coupon-list" scroll-y="true">
					<radio-group @change="checkCoupon">
						<view class="coupon-item" v-for="(item,index) in couponList" :key="index"
							style="margin: 15rpx;">
							<view class="coupon-money" style="width: 25%;">
								<text>￥{{item.money|numFilter}}</text>
							</view>
							<view class="coupon-body">
								<view class="title"><text>{{item.title}}</text></view>
								<view class="info"><text>有效期至：{{item.use_end_time}}</text></view>
								<view class="info"><text>满{{item.condition|numFilter}}可用</text></view>
								<view class="info"><text v-if="item.area_id==0">全区通用</text><text
										v-else>{{item.area_name}}</text></view>
							</view>
							<view class="coupon-status">
								<label class="radio">
									<radio :value="index" :checked="index == curCoupon" color="#000000"
										style="transform:scale(0.8)" />
								</label>
							</view>
						</view>
					</radio-group>
				</scroll-view>
				<view class="coupon-cancel" @click="cancelCoupon"><text>不用优惠券</text></view>
			</view>
		</uni-popup>
		<uni-popup ref="address" type="center" :closeBtn="true">
			<view style="width: 640rpx; background: #F6F6F6; border-radius: 20rpx; padding-bottom: 20rpx;">

				<radio-group @change="checkAddress" style="width: 640rpx;height: 100%;position: relative;">
					<scroll-view class="addr-address-list" scroll-y="true"
						style="width: 94%; height: 600rpx;margin-left: 3%;">
						<view v-for="(item,index) in addressList" :key="index" class="addr-address-box ">
							<view class="addr-address-item1 ">
								<view class="text-bold" style="font-size: 28upx;">
									<text class="address ">{{item.address+item.detail}}</text>
									<text class="is_default" v-if="item.is_default==1">（默认）</text>

								</view>
								<view class="dizhi-info" style="color: #999999;">
									<text class="consignee">{{item.consignee}}</text>
									<text class="mobile ">{{item.mobile}}</text>
								</view>
							</view>
							<view class="addr-address-item2 middle">
								<label class="radio">
									<radio :value="item.address_id" :checked="item.address_id == postData.address_id"
										color="#1270E0" style="transform:scale(0.8)" />
								</label>
							</view>
						</view>
					</scroll-view>
				</radio-group>
				<view class="os-add-addr-btn" @click="addAddress">
					<text>+ 新增地址</text>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import uniPopup from "@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue";
	import ypNumberBox from "@/app/BotWater/components/yp-number-box/yp-number-box.vue";
	export default {
		components: {
			uniPopup,
			ypNumberBox
		},
		data() {
			return {
				domain: this.resDomain,
				isLoading: false, //是否加载完成显示
				loadStatus: 'load',
				scrollH: this.WH - this.CustomBar - 5,
				StatusBar: this.Custom,
				title: "桶装水",
				shop_id: 0,
				payname: '微信',
				cartInfo: {},
				shopinfo: {
					area: {}
				},
				userInfo: {},
				pick_start_time: '9:00',
				pick_end_time: '23:59',
				postData: {
					'shop_id': 0,
					'address_id': 0,
					'is_reserve': 0,
					'take_self': 0,
					'reserve_time': null,
					'user_note': '',
					'origin_type': 0,
					'integral': 0,
					'user_money': 0,
					'goods': {},
					'step': 1,
					'pay_code': 'wxpay',
					'pick_code': 0,
					'orderType': 1,
					'coupon_list_id': 0,

				},
				is_use_money: 0,
				is_use_integral: 0,
				address: {
					'addres_id': 0
				},
				addressList: {},
				orderInfo: {},
				is_sub: 0,
				dateArr: ['今日', '明天', '后天'],
				day: 0,
				goodsList: [],
				goodskey: 0,
				multiIndex: [0, 0],
				multiArray: [
					[],
					[]
				],
				couponList: [],
				cartList: {},
				cartGoodsNum: {},
				cartInfo: {},
				quanName: "",
				params: '', //传递参数存入
			}
		},
		filters: {
			numFilter(value) {
				return parseFloat(value)
			}
		},
		onLoad(option) {
			this.params = option;
			(option.params) ? (() => {
				let params = JSON.parse(option.params);
				this.shop_id = params[0].value;

			})() : (option.shop_id) ? (() => {
				this.shop_id = option.shop_id;
			})() : (() => {
				if (this.shop_id == 0) {
					uni.showModal({
						title: "提示",
						content: "功能即将上线，敬请期待",
						showCancel: false,
						success: (e) => {
							if (e.confirm) {
								uni.navigateBack({
									delta: 1

								})
							}
						}
					})
				}
				return;
			})();
			if (this.shop_id == 0) {
				return false;
			}
			this.postData.shop_id = this.shop_id;
			this.apiRequest('/buyer/shopInfo', {
				shop_id: this.shop_id,
			}, 1).then(res => {
				this.shopinfo = res.data;

				for (let i in res.data.goods) {
					this.multiArray[0].push(res.data.goods[i].cate_name);

				}
				for (let k in res.data.goods[0].goodsList) {
					this.multiArray[1].push(res.data.goods[0].goodsList[k].goods_name);
				}

				this.MultiChange({
					detail: {
						value: [0, 0]
					}
				})


			})

			this.apiRequest('/buyer/userInfo', {
				area_id: uni.getStorageSync('area_id'),
			}).then(res => {

				this.userInfo = res.data
			})

			this.apiRequest('/buyer/addressList', {
				area_id: uni.getStorageSync('area_id'),
			}).then(res => {
				this.addressList = res.data
				if (this.addressList.length > 0) {
					for (var key in this.addressList) {
						if (this.addressList[key].is_default == 1) {
							this.address = this.addressList[key]
						}
					}

					if (this.address.addres_id == 0) { //没有默认地址，就选最新的地址
						this.address = this.addressList[0]
					}

					this.postData.address_id = this.address.address_id
					this.postData.consignee = this.address.consignee
					this.postData.mobile = this.address.mobile
				}
			})
			this.isLoading = true;
			var nowtime = new Date()
			var hour = nowtime.getHours() + 1
			this.postData.reserve_time = this.PrefixZero(hour, 2) + ':' + this.PrefixZero(nowtime.getMinutes(), 2)
			this.pick_start_time = this.postData.reserve_time
		},
		onShow() {
			const res = uni.getStorageSync('cartList-' + this.shop_id);
			if (res) {
				this.cartList = res
			} else {
				this.cartList = {}
			}
			//#ifdef H5
			if (this.isWeiXin()) {
				this.apiRequest('/mobile/index/getWxconfig', {
					url: window.location.href
				}).then(res => {
					this.wxconfig = res.data
				})
			}
			//#endif
		},
		mounted() {
			uni.setStorageSync("selectCoun", "");
		},
		onPullDownRefresh() {
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 500);
		},
		onShareAppMessage(res) {
			let dat = {
				params: '/app/BotWater/pages/index',
				id: this.shop_id,
				key: "shop_id"
			}
			return {
				title: "一舟校园-" + this.title,
				path: "/pages/basic/basic?param=" + JSON.stringify(dat),
			}
		},
		methods: {
			/**
			 * 点击记录
			 */
			clickRecord() {
				uni.navigateTo({
					url: "/app/TakeOut/pages/user/orderList?orderType=BotWater",
					animationType: "slide-in-slide-in-right"
				})
			},
			/**
			 * 更新登录信息
			 */
			upDataLogin() {
				this.apiRequest('/buyer/shopInfo', {
					shop_id: this.shop_id,
				}, 1).then(res => {
					this.shopinfo = res.data;

					for (let i in res.data.goods) {
						this.multiArray[0].push(res.data.goods[i].cate_name);

					}
					for (let k in res.data.goods[0].goodsList) {
						this.multiArray[1].push(res.data.goods[0].goodsList[k].goods_name);
					}
				})

				this.apiRequest('/buyer/userInfo', {
					area_id: uni.getStorageSync('area_id'),
				}).then(res => {
					this.isLoading = true;
					this.userInfo = res.data
				})

				this.apiRequest('/buyer/addressList', {
					area_id: uni.getStorageSync('area_id'),
				}).then(res => {
					this.addressList = res.data
					if (this.addressList.length > 0) {
						for (var key in this.addressList) {
							if (this.addressList[key].is_default == 1) {
								this.address = this.addressList[key]
							}
						}

						if (this.address.addres_id == 0) { //没有默认地址，就选最新的地址
							this.address = this.addressList[0]
						}

						this.postData.address_id = this.address.address_id
						this.postData.consignee = this.address.consignee
						this.postData.mobile = this.address.mobile
					}
				})

				uni.setStorageSync("selectCoun", "");


				var nowtime = new Date()
				var hour = nowtime.getHours() + 1
				this.postData.reserve_time = this.PrefixZero(hour, 2) + ':' + this.PrefixZero(nowtime.getMinutes(), 2)
				this.pick_start_time = this.postData.reserve_time;
				this.getListData();
				const res = uni.getStorageSync('cartList-' + this.shop_id);
				if (res) {
					this.cartList = res
				} else {
					this.cartList = {}
				}
			},

			upData1: function() {
				let time = new Date().getTime(); //获取当前的毫秒数
				this.backEvent = time;
				this.updateAdree();

			},
		
			updateAdree() {
				this.apiRequest('/buyer/addressList', {
					area_id: uni.getStorageSync('area_id'),
				}).then(res => {
					this.addressList = res.data
					if (this.addressList.length > 0) {
						for (var key in this.addressList) {
							if (this.addressList[key].is_default == 1) {
								this.address = this.addressList[key]
							}
						}

						if (this.address.addres_id == 0) { //没有默认地址，就选最新的地址
							this.address = this.addressList[0]
						}

						this.postData.address_id = this.address.address_id
						this.postData.consignee = this.address.consignee
						this.postData.mobile = this.address.mobile
					}
				})
			},
			upData(index) {
				let selectCoun = uni.getStorageSync("selectCoun");

				if (selectCoun > -1) {
					if (this.postData.goods.length == 0) {
						uni.showToast({
							title: '请选择',
							icon: 'none'
						})
						return
					}
					this.postData.coupon_list_id = selectCoun;
					this.getData();
				} else if (selectCoun == -1) {
					this.cancelCoupon();
				} else {
					uni.setStorageSync("selectCoun", 0);
					this.postData.coupon_list_id = 0;

				}
			},
			cart(e) {
				this.postData.goods[0].num = e.num;
				this.getData();
			},
			clearCart() {
				this.cartList = {}
				this.cartInfo = {
					'total_goods_price': 0,
					'goodsList': {}
				}
				this.cartHeight = '0px'
				this.cartGoodsNum = {}
				uni.removeStorageSync('cartList-' + this.shop_id)
				uni.removeStorageSync('cartInfo-' + this.shop_id)
				uni.removeStorageSync('cartGoodsNum-' + this.shop_id)
				uni.showToast({
					title: '购物车已清空',
					duration: 800
				});
			},

			MultiChange(e) {
				this.multiIndex = e.detail.value;
				this.postData.goods[0] = this.shopinfo.goods[this.multiIndex[0]].goodsList[this.multiIndex[1]];
				this.postData.goods[0].num = 1;
				this.getData();
			},
			MultiColumnChange(e) {
				(e.detail.column == 0) ? (() => {
					let arr = [];

					for (let i in this.shopinfo.goods[e.detail.value].goodsList) {
						arr.push(this.shopinfo.goods[e.detail.value].goodsList[i].goods_name);

					}
					this.$set(this.multiArray, 1, arr);
				})() : "";

			},


			selectPay() {
				this.$refs.pay.open()
			},
			checkPay(e) {
				this.postData.pay_code = e.target.value
				this.$refs.pay.close();
			},
			bindPickCode(e) {
				this.postData.pick_code = e.detail.value;
			},
			bindUserNote(e) {
				this.postData.user_note = e.detail.value;
			},
			useIntegral(e) {
				if (e.detail.value.includes('Integral')) {
					this.postData.integral = this.userInfo.integral
					if (this.userInfo.integral > this.cartInfo.online_amount * 200) {
						this.postData.integral = this.cartInfo.online_amount * 200
					}
					this.is_use_integral = 1
				} else {
					this.postData.integral = 0
					this.is_use_integral = 0
				}
				this.getData()
			},
			useMoney(e) {
				if (e.detail.value.includes('user_money')) {
					this.postData.user_money = this.userInfo.money
					if (this.postData.user_money > this.cartInfo.online_amount * 100) {
						this.postData.user_money = this.cartInfo.online_amount * 100
					}
					this.is_use_money = 1
				} else {
					this.postData.user_money = 0
					this.is_use_money = 0
				}
				this.getData()
			},
			selectAddr() {
				this.$refs.address.open()
			},
			checkAddress(e) {
				for (var key in this.addressList) {
					if (e.detail.value == this.addressList[key].address_id) {
						this.address = this.addressList[key]
						this.postData.address_id = e.detail.value
					}
				}
				this.$refs.address.close()
				this.getData()
			},
			addAddress() { //新增地址
				uni.navigateTo({
					url: '/app/TakeOut/pages/user/addressEdit?shop_id=' + this.shop_id
				});
			},
			appointment(e) {
				console.log(e.detail.value)
				this.postData.reserve_time = e.detail.value
				this.postData.is_reserve = 1
			},
			checkDate(e) {
				if (e.detail.value > 0) {
					this.postData.is_reserve = 1
				}
				this.day = e.detail.value
			},
			cancelReserve() { //取消预约
				this.postData.reserve_time = this.pick_start_time
				this.postData.is_reserve = 0
			},
			checkGood(e) {
				this.goodskey = e.detail.value
				var cart = {}
				this.postData.goods = {}
				this.$set(cart, 'goods_id', this.goodsList[this.goodskey].goods_id)
				this.$set(cart, 'num', 1)
				this.$set(cart, 'item', '')
				this.$set(this.postData.goods, this.goodsList[this.goodskey].goods_id, cart)
				this.getData()
			},
			getData() { //获取最新价格
				if (this.postData.goods[0].num <= 0) {
					uni.showToast({
						title: '请选择数量',
						icon: 'none'
					})
					return
				}
				this.apiRequest('/buyer/addOrder', this.postData, 1).then(res => {
					switch (res.code) {
						case 1008:
							this.cancelCoupon();
							return;
							break;
						case 200:

							break;
						default:
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
							return;
							break;

					}
					this.cartInfo = res.data;
					uni.setStorageSync("selectCoun", "");
					this.apiRequest('/buyer/couponList', {
						area_id: uni.getStorageSync('area_id'),
						condition: this.cartInfo.total_goods_price || 0,
						shop_id: this.shop_id,
						type: "all",
						status: 0
					}).then(res => {
						this.couponList = res.data.data;
					});

				})

			},
			subOrder() {
				if (this.is_sub == 1) {
					uni.showToast({
						title: '订单已提交,请不要重复提交',
						icon: 'none'
					})
					return
				}

				if (!this.postData.goods[0]) {
					uni.showToast({
						title: '请选择商品',
						icon: 'none'
					})
					return
				}
				if (this.postData.goods[0].num <= 0) {
					uni.showToast({
						title: '请选择数量',
						icon: 'none'
					})
					return
				}
				this.postData.step = 2;
				this.is_sub = 1;
				this.apiRequest('/buyer/addOrder', this.postData, 1).then(res => {
					this.is_sub = 0;
					if (res.code != 200) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						return
					}
					//清理购物车数据
					uni.removeStorageSync('cartList-' + this.shop_id)
					uni.removeStorageSync('cartInfo-' + this.shop_id)
					uni.removeStorageSync('cartGoodsNum-' + this.shop_id)
					this.orderInfo = res.data
					this.getOrderInfo() //发起支付					
				})
			},
			getOrderInfo() {
				uni.showLoading({
					title: "请求中..."
				});
				var that = this;
				this.apiRequest('/mobile/Payment/payApp', this.orderInfo).then(res => {
					this.orderPay = res.data
					if (res.code != 200) {
						uni.hideLoading();
						this.subscribe('order').then(r => {
							uni.redirectTo({
								url: '/app/TakeOut/pages/order/orderInfo?order_id=' + that
									.orderInfo.order_id
							});
						})
					} else {
						this.requestPay(this.orderInfo.pay_code)
					}
				})
			},
			PrefixZero(num, n) {
				return (Array(n).join(0) + num).slice(-n);
			},
			requestPay(type = 'wxpay') {
				var that = this
				//#ifdef H5
				if (type == 'wxgzh') {
					var jweixin = require('jweixin-module')
					jweixin.config({
						debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
						appId: this.wxconfig.appId, // 必填，公众号的唯一标识
						timestamp: this.wxconfig.timestamp, // 必填，生成签名的时间戳
						nonceStr: this.wxconfig.nonceStr, // 必填，生成签名的随机串
						signature: this.wxconfig.signature, // 必填，签名，见附录1
						jsApiList: ['chooseWXPay'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
					});

					var payInfo = this.orderPay
					jweixin.ready(function() {
						jweixin.chooseWXPay({
							timestamp: payInfo.timeStamp,
							nonceStr: payInfo.nonceStr,
							package: payInfo.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
							signType: payInfo.signType,
							paySign: payInfo.paySign, // 支付签名
							success: function(res) {
								uni.redirectTo({
									url: '/app/TakeOut//pages/order/orderInfo?order_id=' + that
										.orderInfo
										.order_id
								});
							},
							cancel: function(res) {
								uni.redirectTo({
									url: '/app/TakeOut//pages/order/orderInfo?order_id=' + that
										.orderInfo
										.order_id
								});
							},
							fail: function(res) {
								uni.redirectTo({
									url: '/app/TakeOut//pages/order/orderInfo?order_id=' + that
										.orderInfo
										.order_id
								});
							}
						});
					});

					jweixin.error(function(res) {
						uni.redirectTo({
							url: '/app/TakeOut//pages/order/orderInfo?order_id=' + this.orderInfo.order_id
						});
					})
				}
				//#endif


				// #ifndef H5  
				//支付宝支付
				if (type == 'alipay') {
					uni.requestPayment({ //订单提交成功，发起支付
						provider: 'alipay',
						orderInfo: this.orderPay, //微信、支付宝订单数据
						success: function(res) {
							console.log('success:' + JSON.stringify(res));
							uni.redirectTo({
								url: '/app/TakeOut//pages/order/orderInfo?order_id=' + that.orderInfo
									.order_id
							});
						},
						fail: function(err) {
							console.log('fail:' + JSON.stringify(err));
							uni.redirectTo({
								url: '/app/TakeOut//pages/order/orderInfo?order_id=' + that.orderInfo
									.order_id
							});
						}
					});
				}
				//微信支付
				if (type == 'wxpay') {
					console.log(String(this.orderPay.timeStamp))
					uni.requestPayment({ //订单提交成功，发起支付
						provider: 'wxpay',
						appId: this.orderPay.appId,
						timeStamp: String(this.orderPay.timeStamp),
						nonceStr: this.orderPay.nonceStr,
						package: this.orderPay.package,
						signType: this.orderPay.signType,
						paySign: this.orderPay.paySign,
						success: (res) => {
							uni.hideLoading();
							this.subscribe('order').then(r => {
								uni.redirectTo({
									url: '/app/TakeOut/pages/order/orderInfo?order_id=' + that
										.orderInfo
										.order_id
								});
							})
						},
						fail: function(err) {
							uni.hideLoading();
							uni.redirectTo({
								url: '/app/TakeOut/pages/order/orderInfo?order_id=' + that.orderInfo
									.order_id
							});
						}
					});
				}

				// #endif 
			},
			cancelCoupon() {
				this.postData.step = 1
				this.postData.coupon_list_id = 0;
				setTimeout(()=>{
					this.getData()
				},1500)
				
			},
			selectCoupon() {

				if (!this.postData.goods[0]) {
					uni.showToast({
						title: '请先选择商品',
						icon: 'none'
					})
					return
				}


				let params = {
					shop_id: this.shop_id,

				}

				uni.navigateTo({
					url: "/pages/user/coupon?shop_id=" + this.shop_id + "&type=all&id=" + this.postData
						.coupon_list_id + "&status=0&condtion=" + this.cartInfo.total_goods_price
				})
			},
			isWeiXin() { //判断是否微信浏览器
				var ua = window.navigator.userAgent.toLowerCase();
				if (ua.match(/MicroMessenger/i) == 'micromessenger') {
					return true;
				} else {
					return false;
				}
			}

		},
	}
</script>
<style lang="scss">
	.head-item-body1 {
		.title {
			width: 50%;
			padding-left: 0 !important;
			text-overflow: ellipsis;
			overflow: hidden;
			white-space: nowrap;
			text-align: left;
			display: block;
			font-size: calc(100vw*(28/750));
		}
	}
</style>

<style>
	/**
	 * 头部控件
	 */
	.head-bg {
		color: white;
		background-color: #3589F7;
	}


	.head-style1 {
		width: 100vw;
		/* height: 750upx; */
		background-size: cover;
		background-position: left top;
		background-repeat: no-repeat;
		background-color: #3589F7;

	}

	.addressT {

		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		display: flex;
		flex-direction: row;
		align-items: baseline;
		margin-top: 10upx;
		font-size: 24upx;
		font-weight: 500;
		color: #999999;
	}

	.addressT1 {
		width: 100%;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.biaoti {
		width: 60vw;
		display: flex;
		align-items: center;
		margin-left: 3vw;
		font-weight: 600;
		color: white;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.water-box {
		width: 94%;
		margin-left: 3%;
		display: flex;
		flex-direction: column;
	}

	.water-box-address {
		width: 100%;
		height: 250upx;
		background: #FFFFFF;
		box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.05);
		border-radius: 20upx;

	}

	.iconlocation {
		color: #FF1270E0;
	}

	.select-postion-t {
		text-align: left;
	}

	.cu-form-group {
		height: 50%;
		border: none;
		border-radius: 20upx;
	}

	.water-box-title1 {
		text-overflow: ellipsis;
		white-space: nowrap;
		overflow: hidden;
		display: flex;
		align-items: center;
		height: 100upx;
		position: relative;
		text-align: right;
		width: 50%;
	}

	.water-box-title2 {
		text-overflow: ellipsis;
		white-space: nowrap;
		overflow: hidden;
		display: flex;
		align-items: center;
		height: 100upx;
		position: relative;
		text-align: right;
		width: 100%;
	}

	.picer-right-box {
		text-align: right;
		width: 90%;
		height: 100upx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}

	.unit-box {
		width: 90%;
		text-overflow: ellipsis;
		white-space: nowrap;
		overflow: hidden;

	}

	.water-num-box {
		width: 100%;
		height: 100upx;
		background: #FFFFFF;
		box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.05);
		border-radius: 20upx;
		display: flex;
		flex-direction: row;
		align-items: center;
		position: relative;
	}

	.water-item-right {
		position: absolute;
		float: right;
		right: 30rpx;
	}

	.water-item-right1 {

		position: absolute;
		float: right;
		right: 0%;
	}

	.youhuiquan {
		color: white;
		background-color: #FFDF3636;
	}

	.water-bottom-box {
		width: 100%;
		font-size: 22upx;
		font-weight: 500;
		color: #FFFFFF;
		padding-bottom: 20upx;
	}

	.water-box-bottom {
		width: 94%;
		margin-left: 3%;
		margin-top: 5%;

	}

	.pay-box {
		width: 100%;
		margin-top: 40upx;
		background: #FFFFFF;
		box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.05);
		border-radius: 20upx;
		flex-direction: column;


	}

	.pay-box-item {
		width: 96%;
		height: 100upx;
		position: relative;
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.pay-booton {
		width: 96%;
		height: 120upx;
		position: relative;
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.jifen {
		font-size: 24upx;
		font-weight: 500;
		color: #999999;
	}

	.cuIcon-weixin {
		font-size: 65upx;
	}

	.price {
		padding: 0 4upx 0 4upx;
	}

	.pay-buuton-box {
		width: 250upx;
		height: 80upx;
	}

	.icon-img {
		width: 50%;
		height: 80%;

	}

	.title {
		display: flex;
		align-items: center;
		padding-left: 10upx;
	}

	.picker-box {
		width: 100% !important;
		text-align: right;
		display: flex;
		flex-direction: row;
		position: relative;
	}

	.picker-box1 {
		display: flex;
		align-items: center;
		height: 100%;
		width: 100%;
		justify-content: end;

	}

	.oi-deduct {
		background: #FFFFFF;
		padding: 2% 1% 2% 5%;
		margin-bottom: 15rpx;
	}

	.addr-address-item1 view {
		width: 100%;
		height: 40%;
		display: flex;
		align-items: center;
		line-height: 1.5;
	}

	.oi-deduct-item {
		margin-top: 15rpx;
		display: flex;
		justify-content: space-between;
	}

	.oi-deduct-item .minusfee {
		color: #FF0000;
		font-size: 24rpx;
	}

	.oi-deduct-item .use-able {
		font-size: 24rpx;
	}

	.coupon-cancel {
		width: 640rpx;
		background: #FFFFFF;
		text-align: center;
		height: 60rpx;
		line-height: 60rpx;
		margin-top: 15rpx;

	}

	.note-tip {
		width: 100%;
		height: 100%;
		font-size: 28rpx;
		color: #666666;
		font-weight: bold;
	}

	.sub-coupon-list {
		background: #FFFFFF;
		height: 780rpx;
		width: 640rpx;
		padding: 0;
	}

	.os-self-tit {
		width: 120rpx;
	}

	checkbox-group {
		display: inline !important;
	}

	.os-add-addr-btn {
		background-color: #1270E0;
		color: #FFFFFF;
		border-radius: 20rpx;
		text-align: center;
		padding: 3%;
		width: 80%;
		margin: 0 auto;
	}

	.sub-pay-box {
		padding: 0% 3% 0 3%;
		display: flex;
		align-items: center;
		width: 94%;
		height: 100upx;
		margin-left: 3%;
		position: fixed;
		bottom: 1vh;
		z-index: 99;
		display: flex;
		flex-direction: row;
		background: #FFFFFF;
		box-shadow: 0px 0px 10upx 0px rgba(0, 0, 0, 0.05);
		border-radius: 20upx;
		position: relative;
	}

	.zhifu {
		position: absolute;
		float: right;
		right: 3%;
		width: 32%;
	}

	.os-pay-left {
		display: flex;
		align-items: center;

	}

	.paySelect {
		position: absolute;
		float: right;
		right: 2%;
	}

	.time-item-tit {
		display: flex;
		align-items: center;
	}

	.weipay {
		height: 50%;
		margin-right: 10upx;
	}

	.uerHead1 {
		color: white;
		background-color: #3589F7;
	}

	.cuIcon-right {
		font-size: 34rpx;
		color: #8799a3;
	}


	/**
	 * 新追加的代码
	 */
	.head-item-box {
		width: 98%;
		height: 46%;

		display: flex;
		flex-direction: row;
		align-items: center;
		position: relative;
	}

	.iconbox {
		width: 10%;
		height: 100%;

	}

	.iconbox text {
		display: flex;
		align-items: center;
	}

	.head-item-body {
		width: 90%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.head-item-body1 {
		width: 100%;
		height: 90%;
		display: flex;
		flex-direction: row;
		align-items: center;
		position: relative;

	}

	.c-text1 {

		width: 100%;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		display: flex;
		align-items: center;
		flex-direction: row;
		font-size: 40upx;
		font-weight: 800;
		color: #333333;
		display: block;
	}

	.right-icon {
		position: absolute;
		right: 0%;
		float: right;
		text-align: center;
	}

	.consignee {
		max-width: 100%;
		white-space: normal;
		word-wrap: break-word;
		margin-right: 20upx;
	}

	.consignee1 {
		display: flex;
		flex-direction: row;
		width: 100%;
		margin-top: 10upx;

		align-items: center;
	}

	.c-text {
		max-width: 50%;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		font-size: 24upx;
		font-weight: 500;
		color: #999999;
		display: block;
	}

	.pickBox {
		width: 100%;
		display: flex;
		flex-wrap: nowrap;
		position: absolute;
		align-items: center;
		height: 100%;

	}

	.payBox {
		width: 96vw;
		margin-left: 2vw;
		position: fixed;
		bottom: 1vh;
		z-index: 999;
	}

	/**** addressList *****/
	.addr-address-list {
		width: 90%;
		margin-left: 5%;
	}

	.addr-address-box {
		margin-top: 15upx;
		display: flex;
		justify-content: space-between;
		width: 100%;
		padding: 0 3% 0 3%;
		min-height: 120upx;
		align-items: center;
		background-color: #FFFFFF;
		border-bottom: solid 1rpx #EEEEEE;
		box-shadow: 0px 0px 10upx 0px rgba(0, 0, 0, 0.05);
		border-radius: 20upx;
	}

	.addr-address-item {
		display: flex;
		justify-content: space-between;
		width: 100%;
		padding: 3% 0;
		height: 120upx;
		background-color: #FFFFFF;
		border-bottom: solid 1rpx #EEEEEE;
	}

	.addr-address-item1 {
		width: 85%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: flex-start;
		/* white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden; */
	}

	.addr-address-item2 {
		width: 10%;
		height: 100%;
	}

	.addr-address-item .consignee {
		font-size: 24rpx;
		color: #333333;
	}

	.addr-address-item .mobile {
		margin-left: 15rpx;
		font-size: 24rpx;
		color: #333333;
	}

	.addr-address-item .default {
		color: #000000;
		font-size: 20rpx;
		font-weight: bold;
		margin-left: 15rpx;
	}

	.addr-address-item:last-of-type {
		border: none;
	}

	.addr-add-btn {
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		position: fixed;
		bottom: 0;
		background: #1270e0;
	}

	.is_default {
		font-size: 24rpx;
		font-weight: bold;
		margin-left: 15rpx;
		color: #1270e0;
	}

	.detailimg {
		position: absolute;
		bottom: 210upx;

	}

	.gDetail-info {
		position: absolute;
		z-index: 1;
		min-height: 150upx;
		bottom: 0;
		background-color: white;
	}

	.oi-shouhuo {
		width: 40%;
		text-align: left;
		display: flex;
		align-items: center;
	}

	.dizhi-info {
		display: flex;
		flex-wrap: wrap;
	}
</style>
